package srm514;


public class MagicalGirlLevelOneDivTwo {
    public double theMinDistance(int d, int x, int y) {
        int dx= 0, dy=0;
        if (Math.abs(x) <= d && Math.abs(y) <= d)
            return 0;
        if (Math.abs(x) <= d) {
            ;
        } else if (x > 0) {
            dx = x - d;
        } else {
            dx = (-x) - d;
        }
        if (Math.abs(y) <= d) {
            ;
        }
        else if (y > 0) {
            dy = y - d;
        } else {
            dy = (-y) - d;
        }
        return Math.sqrt(dx * dx + dy * dy);
    }

    // BEGIN KAWIGIEDIT TESTING
    // Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
    private static boolean KawigiEdit_RunTest(int testNum, int p0, int p1, int p2, boolean hasAnswer, double p3) {
        System.out.print("Test " + testNum + ": [" + p0 + "," + p1 + "," + p2);
        System.out.println("]");
        MagicalGirlLevelOneDivTwo obj;
        double answer;
        obj = new MagicalGirlLevelOneDivTwo();
        long startTime = System.currentTimeMillis();
        answer = obj.theMinDistance(p0, p1, p2);
        long endTime = System.currentTimeMillis();
        boolean res;
        res = true;
        System.out.println("Time: " + (endTime - startTime) / 1000.0 + " seconds");
        if (hasAnswer) {
            System.out.println("Desired answer:");
            System.out.println("\t" + p3);
        }
        System.out.println("Your answer:");
        System.out.println("\t" + answer);
        if (hasAnswer) {
            res = Math.abs(p3 - answer) <= 1e-9 * Math.max(1.0, Math.abs(p3));
        }
        if (!res) {
            System.out.println("DOESN'T MATCH!!!!");
        } else if ((endTime - startTime) / 1000.0 >= 2) {
            System.out.println("FAIL the timeout");
            res = false;
        } else if (hasAnswer) {
            System.out.println("Match :-)");
        } else {
            System.out.println("OK, but is it right?");
        }
        System.out.println("");
        return res;
    }

    public static void main(String[] args) {
        boolean all_right;
        all_right = true;

        int p0;
        int p1;
        int p2;
        double p3;

        // ----- test 0 -----
        p0 = 5;
        p1 = 10;
        p2 = 10;
        p3 = 7.0710678118654755D;
        all_right = KawigiEdit_RunTest(0, p0, p1, p2, true, p3) && all_right;
        // ------------------

        // ----- test 1 -----
        p0 = 5;
        p1 = 10;
        p2 = 3;
        p3 = 5.0D;
        all_right = KawigiEdit_RunTest(1, p0, p1, p2, true, p3) && all_right;
        // ------------------

        // ----- test 2 -----
        p0 = 5;
        p1 = -8;
        p2 = -6;
        p3 = 3.1622776601683795D;
        all_right = KawigiEdit_RunTest(2, p0, p1, p2, true, p3) && all_right;
        // ------------------

        // ----- test 3 -----
        p0 = 5;
        p1 = 3;
        p2 = 2;
        p3 = 0.0D;
        all_right = KawigiEdit_RunTest(3, p0, p1, p2, true, p3) && all_right;
        // ------------------

        // ----- test 4 -----
        p0 = 24;
        p1 = 24;
        p2 = -24;
        p3 = 0.0D;
        all_right = KawigiEdit_RunTest(4, p0, p1, p2, true, p3) && all_right;
        // ------------------

        // ----- test 5 -----
        p0 = 345;
        p1 = -471;
        p2 = 333;
        p3 = 126.0D;
        all_right = KawigiEdit_RunTest(5, p0, p1, p2, true, p3) && all_right;
        // ------------------

        if (all_right) {
            System.out.println("You're a stud (at least on the example cases)!");
        } else {
            System.out.println("Some of the test cases had errors.");
        }
    }
    // END KAWIGIEDIT TESTING
}
//Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!
